package com.hsurosy.domain.activity.service.quota.policy.impl;

import com.hsurosy.domain.activity.model.aggregate.CreateQuotaOrderAggregate;
import com.hsurosy.domain.activity.model.valobj.OrderStateVO;
import com.hsurosy.domain.activity.repository.IActivityRepository;
import com.hsurosy.domain.activity.service.quota.policy.ITradePolicy;
import org.springframework.stereotype.Service;

/**
 * @Author Hsu琛君珩
 * @Date 2024-11-25 17:41
 * @Description 信用支付交易策略
 * @Version: v1.0.0
 */
@Service("credit_pay_trade")
public class CreditPayTradePolicy implements ITradePolicy {

    private final IActivityRepository activityRepository; // 活动仓储接口

    public CreditPayTradePolicy(IActivityRepository activityRepository) {
        this.activityRepository = activityRepository;
    }

    /**
     * 信用支付交易逻辑的实现
     * 将订单状态设置为待支付状态，并通过活动仓储接口保存信用支付订单
     *
     * @param createQuotaOrderAggregate 创建订单的聚合对象，包含订单相关的所有数据
     */
    @Override
    public void trade(CreateQuotaOrderAggregate createQuotaOrderAggregate) {
        // 设置订单状态为待支付
        createQuotaOrderAggregate.setOrderState(OrderStateVO.wait_pay);
        // 调用仓储接口保存信用支付订单
        activityRepository.doSaveCreditPayOrder(createQuotaOrderAggregate);
    }

}
